import type { ResponeData } from '@/types/HttpType'

import {env} from '@/utils/env'
import http from './http'
import axios from 'axios';

export const uploadFile = async (type:number,data:any, onUploadProgress:Function, source?:any):Promise<string> => {
  
         let res = await http<string[]>({
            url: env.VITE_ZHER_SUPPORT + '/file/upload/' + type,
            method: 'post',
            data,
            headers: {
                'Content-Type': 'multipart/form-data'
            },
            cancelToken: source?.token ,
            // cancelToken: new CancelToken(function executor(c) {
            //     // 保存cancel函数以便后续调用
                
            //     cancel = c;
               
            //     window.luqiCancel = c
            //   }),
            onUploadProgress: (e) => {
                onUploadProgress(e)
            }
        })

        return res.data[0]
    
}

export const auth = async (userId:number):Promise<ResponeData<string>> => {
   
        return http({
            url: env.VITE_ZHER_SUPPORT + '/auth/token/' + userId,
            method: 'get',
            
        })
    
}
